﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Twin
{
    class KGet
    {
        public static int unsignedByte(byte data){      //将data字节型数据转换为0~255 (0xFF 即BYTE)。
            return data&0x0FF;
        }

        public static int unsignedShort(short data){     //将data字节型数据转换为0~65535 (0xFFFF 即 WORD)。
            return data&0x0FFFF;
        }
       
        public static long unsignedInt(int data){       //将int数据转换为0~4294967295 (0xFFFFFFFF即DWORD)。
            return data&0x0FFFFFFFF;
        }
    
        public static short Short(byte[] b, int index){
            //return (short)((b[index + 1] << 8) | (b[index] << 0));
            int[] d = new int[2];  
          
            for (int i = 0; i < 2; i++) {  
                d[i] = ((b[index + i]) >= 0 ? b[index + i] : 256 + b[index + i]);   
            }  
  
            return (short)((d[1] << 8) | (d[0] << 0));
        }  
  
    
        public static int Int(byte[] b, int index)
        {
            int[] d = new int[4];  
          
            for (int i = 0; i < 4; i++) {  
                d[i] = ((b[index + i]) >= 0 ? b[index + i] : 256 + b[index + i]);   
            }  
  
            return ((d[3] << 24) | (d[2] << 16) | (d[1] << 8) | (d[0] << 0));  
        }
    
        public static String HHmmSS(){
            String s = DateTime.Now.ToString("hh:mm:ss");
            return s;
        }
    
        //2018_09_12
        /*
        public static String YY_MM_DD(){
            String s = "";
            s = String.format("%04d", Calendar.getInstance().get(Calendar.YEAR))
                +"_" + String.format("%02d", Calendar.getInstance().get(Calendar.MONTH) + 1)
                +"_" + String.format("%02d", Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
                //+"." + String.format("%03d", Calendar.getInstance().get(Calendar.MILLISECOND));
            return s;
        }
    
        //180912
        /*
        public static String shortYYMMDD(){
            String s = "";
            s = String.format("%02d", Calendar.getInstance().get(Calendar.YEAR) - 2000)
                 + String.format("%02d", Calendar.getInstance().get(Calendar.MONTH) + 1)
                 + String.format("%02d", Calendar.getInstance().get(Calendar.DAY_OF_MONTH));
                //+"." + String.format("%03d", Calendar.getInstance().get(Calendar.MILLISECOND));
            return s;
        }
    
        //HHmmSS
        public static String shortHHmmSS(){
            String s = "";
            s = String.format("%02d", Calendar.getInstance().get(Calendar.HOUR_OF_DAY))
                + String.format("%02d", Calendar.getInstance().get(Calendar.MINUTE))
                + String.format("%02d", Calendar.getInstance().get(Calendar.SECOND));
            return s;
        }*/
     
    }
}
